# coding=utf-8
from django.db import models
from django.contrib.auth.models import User

ADTYPE_CHOICES = (
    ('i', '图片广告'),
    ('f', 'Flash广告'),
)

AD_PAGES = (
    ('homepage', '网站首页'),
    ('channel_page', '一级频道页面'),
    ('subchannel_page', '二级频道页面'),
    ('detail_page', '文章页面'),
)

AD_BLOCKS = (
    (1, '顶部通栏广告1'),
    (2, '顶部通栏广告2'),
    (3, 'H栏目标题广告'),
    (4, 'H右侧展示广告'),
    (5, 'H左侧横幅广告'),
    (6, 'H首页下方通栏广告'),
    (7, 'C1顶部通栏广告'),
    (8, 'C1标题展示广告'),
    (9, 'C1右侧展示广告'),
    (10, 'C2顶部通栏广告'),
    (11, 'C2标题展示广告'),
    (12, 'C2右侧方形广告'),
    (13, 'D顶部通栏广告'),
    (14, 'D标题展示广告'),
    (15, 'D右侧方形广告'),
)

class AdBlock(models.Model):
    name = models.CharField(max_length=100, verbose_name="广告位")
    page = models.CharField(max_length=20, choices=AD_PAGES, default="home", verbose_name="广告所在页面")
    remark = models.CharField(blank=True,max_length=300, verbose_name="备注")

    class Meta:
        verbose_name="广告位"
        verbose_name_plural="广告位"

    def __unicode__(self):
        return self.name

class AdItem(models.Model):
    name = models.CharField(max_length=100, verbose_name="名称", help_text="可以输入公司名称或者广告宣传语等")
    ad_type = models.CharField(max_length=1, choices=ADTYPE_CHOICES, default="i", verbose_name="广告类型")
    ad_block = models.ForeignKey(AdBlock, verbose_name="所属广告位", help_text="如需新增广告位，请联系相关管理人员")
    #ad_block_id = models.IntegerField(choices=AD_BLOCKS, default=1, verbose_name="广告所在页面")
    ad_text = models.CharField(max_length=100, verbose_name="广告文字")
    ad_file = models.FileField(upload_to="ads/", max_length=300, verbose_name="广告图片/Flash")
    ad_link = models.URLField(max_length=500, verbose_name="广告跳转网页地址", help_text="例如：http://www.xmdj123.com/")
    editor = models.ForeignKey(User, verbose_name="网站编辑")
    created = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
    updated = models.DateTimeField(auto_now=True, verbose_name="修改时间")

    class Meta:
        verbose_name = "广告项"
        verbose_name_plural = "广告项"

    def __unicode__(self):
        return self.name
